function upload_file(id) {

    $.layer({
        type: 2,
        shade: [0],
        fix: false,
        title: '上传文件',
        maxmin: true,
        iframe: {src: b_url + '/file/add?doc_id=' + id},
        area: ['600px', '300px'],
        close: function(index) {

        }
    });
}

function selete_file(id) {
    $.layer({
        type: 2,
        shade: [0],
        fix: false,
        title: '选择文件',
        maxmin: true,
        iframe: {src: b_url + '/file/index?doc_id='+id},
        area: ['650px', '550px'],
        close: function(index) {
            
        }
    });
}

function preview_file(id) {
    var src = $('#'+id).val();
    if(src == ''){
        return ;
    }
    $.layer({
        type: 2,
        shade: [0],
        fix: false,
        title: '图片预览',
        maxmin: true,
        iframe: {src: src},
        area: ['500px', '300px'],
        close: function(index) {
            
        }
    });
}

//选择文件
function selectfile(obj, val) {
    parent.document.getElementById(obj).value = val;
    parent.layer.closeAll();
}

function GoTo(Url)//转到页面 
{
    window.location.href = Url;
    return false;
}

function SearchDialog()//查询 
{
    var width = "600";
    var height = "";
    $("#floatBoxBg").css("height:" + $(document).height() + "px;");
    $("#floatBoxBg").show();
    $("#floatBoxBg").animate({opacity: "0.5"}, "normal");
    $("#floatBox").attr("class", "floatBox");
    $("#floatBox").css({display: "block", left: (($(document).width()) / 2 - (parseInt(width) / 2)) + "px", top: ($(document).scrollTop() + 50) + "px", width: width, height: height});
    $("#floatBox .title span").click(function() {
        $("#floatBoxBg").hide();
        $("#floatBox").hide();
    });
}

function HiddenSearchDialog()//隐藏查询对话框
{
    $("#floatBoxBg").hide();
    $("#floatBox").hide();
}

function checkOperate(obj)//检查要操作的记录数 
{
    var name = $(obj).attr('name');
    var num = $('input[name="' + name + '"]:checked').size();
    if (num == 0) {
        layer.alert("请选择您要操作的一条或多条记录!");
        return false;
    }
    var arr_v = new Array();
    $('input[name="' + name + '"]:checked').each(function() {
        arr_v.push(this.value);
    });
    GoTo($(obj).attr('src') + arr_v.join('.'));
}

function checkEdit(obj)//检查要修改的记录数 
{
    var name = $(obj).attr('name');
    var num = $('input[name="' + name + '"]:checked').size();
    if (num != 1) {
        layer.alert('请选择您要操作的一条记录');
        return false;
    }
    var val = $('input[name="' + name + '"]:checked').val();
    GoTo($(obj).attr('src') + val);
}

function checkDel(obj)//检查要删除的记录数 
{
    var name = $(obj).attr('name');
    var num = $('input[name="' + name + '"]:checked').size();
    if (num == 0) {
        layer.alert("请选择您要删除的一条或多条记录!");
        return false;
    }
    layer.confirm('记录删除后将不能进行恢复操作，您真的要删除这些记录吗？', function(index) {
        //操作
        var arr_v = new Array();
        $('input[name="' + name + '"]:checked').each(function() {
            arr_v.push(this.value);
        });
        GoTo($(obj).attr('src') + arr_v.join('.'));
    });

}
function createFolder() {
    var pageii = $.layer({
        type: 1,
        title: '创建文件夹',
        area: ['auto', 'auto'],
        page: {
            html: '<div style="width:260px; height:80px; padding:20px;"><p>文件夹名称：<input type="text" name="" id="folder_name"/></p> <span class="xubox_botton"><a class="xubox_botton1" href="javascript:create_folder();">确定</a></span></div>'
        }
    });
}
function create_folder() {
    var str = $('#folder_name').val().trim();
    //是否包含: * ? < > \ / "
    if (new RegExp("[\\/\:\?\"<>\*]+").test(str))
    {
        layer.msg('输入合法的文件名称'); //风格二
        return;
    }
    var dr = $('#drpFolderPath').val();
    $.ajax({
        type: "POST",
        url: b_url + "/file/create_folder",
        data: 'foldername=' + str + '&dir=' + dr,
        dataType: 'json',
        beforeSend:
                function() {
                    layer.load('文件创建中,请稍候……', 20);
                },
        success:
                function(data) {
                    if (data.code == 1) {
                        location.reload();
                    } else {
                        layer.msg(data.msg, 2);
                    }
                }
    });

}

function checkDelFolder(obj)//检查要删除的文件夹 
{
    var name = $(obj).attr('name');
    var num = $('input[name="' + name + '"]:checked').size();
    if (num == 0) {
        layer.alert("请选择您要删除的一个或多个文件(夹)");
        return false;
    }
    layer.confirm("文件(夹)删除后将不能进行恢复操作，您真的要删除这些文件(夹)吗？", function(index) {
        //操作
        var arr_v = new Array();
        $('input[name="' + name + '"]:checked').each(function() {
            arr_v.push(this.value);
        });

        var dr = $('#drpFolderPath').val();
        $.ajax({
            type: "POST",
            url: b_url + "/file/del_file",
            data: 'file=' + arr_v.join('/') + '&dir=' + dr,
            dataType: 'json',
            beforeSend:
                    function() {
                        layer.load('文件删除中,请稍候……', 20);
                    },
            success:
                    function(data) {
                        if (data.code == 1) {
                            location.reload();
                        } else {
                            layer.msg(data.msg, 2);
                        }
                    }
        });
    });
}

//function checkDelFile(obj)//检查要删除的文件夹 
//{
//    var c_obj = document.getElementsByName(obj);
//    var num = 0;
//    for (var i = 0; i < c_obj.length; i++) {
//        if (c_obj[i].checked == true)
//            num += 1;
//    }
//    if (num == 0) {
//        layer.alert("请选择您要删除的一个或多个文件!");
//        return false;
//    }
//    else {
//        layer.confirm("文件删除后将不能进行恢复操作，您真的要删除这些文件吗？", function() {
//            __doPostBack('lbtnDelFile', '');
//            return true;
//        }, function() {
//            return true;
//        })
//        return false;
//    }
//}

/////////////////////文件上传/////////////////////////////////// 
//检查文件是否存在
function FileExitsCheck() {
    return;
    var file1 = document.getElementById("InputFile1");
    var FolderPath = document.getElementById("hidFolderPath").value;
    if (file1.value != "") {
        var url;
        if (window.navigator.userAgent.indexOf("Firefox") > -1) {//Firefox
            var FileName = file1.value;
        }
        else {
            var Flen = file1.value.length;
            var Flast = file1.value.lastIndexOf("\\");
            var FileName = file1.value.substring(Flast + 1, Flen);
        }
        $.ajax({
            type: "POST",
            url: b_url + "/file/exists",
            data: "folderpath=" + escape(FolderPath) + "&filename=" + escape(FileName) + "&rnd=" + Math.round(Math.random() * 500),
            beforeSend:
                    function() {
                    },
            success:
                    function(data) {
                        if (data == 1) {
                            layer.confirm("您要上传的文件已存在,您要采用自动命名方式上传此文件吗?", function() {
                                document.getElementById("radNameType_0").checked = false;
                                document.getElementById("radNameType_1").checked = true;
                            }, function() {
                                document.getElementById("radNameType_0").checked = true;
                                document.getElementById("radNameType_1").checked = false;
                            });
                        }
                    }
        });
    }
}

//上传文件检查
function FileFormCheck() {
    var file1 = document.getElementById("InputFile1");
    if (file1.value == "") {
        layer.alert("请选择您要上传的文件!");
        file1.focus();
        return false;
    }
    else {
        //  document.getElementById("UploadProgressBar1").style.display = "block";
        return true;
    }
}


//图片预览
function FilePreview(W, H) {
    try {
        var divPreview = document.getElementById("divPreview");
        var ImgPreviewSize = document.getElementById("ImgPreviewSize");
        var file1 = document.getElementById("InputFile1");
        var exts = "jpg,gif,bmp,png";
        var val;
        var l;
        var ext;
        var IEVer = window.navigator.userAgent;
        if (IEVer.indexOf("Firefox") > -1)//Firefox
        {
            val = file1.value;
            l = val.length;
            ext = val.substring(l - 3, l);
            if (exts.indexOf(ext) > -1) {
                divPreview.style.display = "block";
                var imgSrc = window.URL.createObjectURL(file1.files[0]);
                divPreview.innerHTML = "<img id='ImgID' src='" + imgSrc + "' onload=\"DrawImage('ImgID', " + W + ", " + H + ")\"/>";
            }
            else {
                divPreview.style.display = "none";
            }
        }
        else if (IEVer.indexOf("MSIE") > -1) {
            file1.select();
            val = document.selection.createRange().text;
            l = val.length;
            ext = val.substring(l - 3, l);
            if (exts.indexOf(ext) > -1) {
                //divPreview.style.display = "block";
                if (IEVer.indexOf("MSIE 8") > -1) {//ie8
                    divPreview.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = val;
                    ImgPreviewSize.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = val;
                    divPreview.style.width = 450;
                    divPreview.style.height = 350;
                }
                else if (IEVer.indexOf("MSIE 7") > -1)//ie7
                {
                    divPreview.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = val;
                    divPreview.style.width = 450;
                    divPreview.style.height = 350;
                }
                else//ie6
                {
                    divPreview.innerHTML = "<img id='ImgID' src='" + file1.value + "' onload=\"DrawImage('ImgID', " + W + ", " + H + ")\"/>";
                }
            }
            else {
                //divPreview.style.display = "none";
            }
        }
        else {
            //do nothing
        }
    }
    catch (e) {
    }
}


//隐藏文件选择对话框
function HiddenDialog() {
    parent.document.getElementById("floatBoxBg").style.display = "none";
    parent.document.getElementById("floatBox").style.display = "none";
}

//选择文件夹
function SelectFolder(ObjName) {
    var obj = document.getElementById("drpFolderPath");
    var val = obj.options[obj.selectedIndex].value;
    if (val != "") {
        window.location.href = "?&path=" + val;
    }
}
function show_pic(id) {
    var i = $.layer({
        type: 1,
        title: false,
        fix: false,
        offset: ['50px', ''],
        area: ['auto', 'auto'],
        page: {dom: id}
    });
}
//读取拼音
function GetPinYin(id1, id2) {
    $.ajax({
        type: "get",
        url: b_url + "/columns/pinyin",
        data: "cn=" + $("#" + id1).val() + "&rnd=" + Math.round(Math.random() * 500),
        dataType: 'json',
        beforeSend:
                function() {
                },
        success:
                function(data) {
                    $("#" + id2).val(data.pinyin);
                }
    });
}


//测试邮件配置
function TestMailConfig(fm) {
    $.ajax({
        type: "POST",
        url: "../Ajax/Ajax_TestMailConfig.ashx",
        data: $("#" + fm).serialize() + "&rnd=" + Math.round(Math.random() * 500),
        beforeSend:
                function() {
                },
        success:
                function(data) {
                    alert(data);
                }
    });
}

function selete_tips(obj) {
    if (obj.val() <= 0) {
        $('#' + obj.attr('name') + '_tips').show();
        return false;
    }
    $('#' + obj.attr('name') + '_tips').hide();
    return true;
}

function input_tips(obj) {
    var is = true;
    if (obj.val() == '') {
        $('#' + obj.attr('name') + '_tips').show();
        is = false;
    }else{
        $('#' + obj.attr('name') + '_tips').hide();
    }
    
    if(obj.attr('num')=='true' && obj.val() != ''){
        var re=/^\d+$/;
        if(!re.test(obj.val())){
            $('#' + obj.attr('name') + '_num_tips').show();
            is = false;
        }else{
            $('#' + obj.attr('name') + '_num_tips').hide();
        }
    }    
    return is;
}


